from django.shortcuts import render
from django.views import View
from apps.contents.models import ContentCategory
from apps.contents.utils import get_categories



class IndexView(View):
    def get(self,request):
        # 1.商品数据分类显示
        categories = get_categories()
        # 2.广告数据分类显示
        contents = {}
        # 获取所有的广告分类
        ad_categories = ContentCategory.objects.all()
        # 遍历所有的广告分类，获得所有的广告信息
        for ad_cat in ad_categories:
            contents[ad_cat.key] = ad_cat.content_set.filter(status = True).order_by('sequence')
        context = {
            'categories':categories,
            'contents':contents
        }
        # print('*'*50)
        # print(len(categories),categories)
        print(context)
        return render(request,'index.html', context)